package DailyPractice.Day5;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 连续子数组和最大
 * @author lumin
 * @date 2022/04/23 11:16
 **/
public class Num2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int[] arr = new int[m];
        for (int i = 0; i < m; i++) {
            arr[i] = sc.nextInt();
        }
        int midNum = 0;
        int maxNum = Integer.MIN_VALUE;
        for (int i = 0; i < m; i++) {
            //midNum记录了arr[i]之前的最大值
            midNum = Math.max(midNum + arr[i],arr[i]);
            maxNum = Math.max(midNum,maxNum);
        }
        System.out.println(maxNum);
    }
}